package com.example.rocketmq.timewheel.config;

import io.netty.util.HashedWheelTimer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * 时间轮配置
 */
@Configuration
public class TimeWheelConfig {
    
    @Value("${timewheel.tick-duration}")
    private long tickDuration;
    
    @Value("${timewheel.wheel-size}")
    private int wheelSize;
    
    /**
     * 配置HashedWheelTimer实例
     */
    @Bean
    public HashedWheelTimer hashedWheelTimer() {
        // 创建时间轮实例
        return new HashedWheelTimer(
                tickDuration,  // 每tick的时间间隔
                TimeUnit.MILLISECONDS,  // 时间单位
                wheelSize  // 时间轮大小
        );
    }
}
